﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CommonLibrary;
using DBO.Utility;
using ClientDataAccess.PlayerServiceReference;
using DBO;

namespace ClientDataAccess
{
    public class ClientSessionHandler : ISessionDataAccess
    {
        public ClientSessionHandler()
        {
            Client = new PlayerServiceReference.SOAPPlayerServiceClient();
            Client.Open();
        }

        public string TryLogin(PLICCredentials Creds)
        {
            RequestResponse Resp = Client.OpenSession(Creds);
            //Client.Close();
            return Resp.ErrorMessage == "" ? Resp.Token : null;
        }

        public bool CreateUser(PLICCredentials Creds, System.Net.Mail.MailAddress Address, string Race)
        {
            RequestResponse Resp = Client.CreateUser(Address.Address, Creds, Race);
            return Resp.ErrorMessage == "";
        }

        public string ChangePassword(string Login, System.Net.Mail.MailAddress Address)
        {
            Client.RegeneratePass(Login, Address.ToString());
            return "Mail sent.";
        }

        public Player GetPlayerInfo(string token)
        {
            return Client.GetPlayerInfo(token);
        }

        private PlayerServiceReference.SOAPPlayerServiceClient Client;

    }
}
